package com.superlc.ssm.modular.api.controller;

import com.superlc.ssm.common.util.ResponseEntity;
import com.superlc.ssm.common.util.ResponseUtils;
import com.superlc.ssm.core.common.annotation.Log;
import com.superlc.ssm.modular.api.model.UserOnline;
import com.superlc.ssm.modular.api.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author super
 */
@RestController
@RequestMapping("/api/online")
public class UserOnlineController {

    @Autowired
    private SessionService sessionService ;

    //@JsonView(UserApiJsonView.class)
    @RequestMapping("/list")
    public @ResponseBody List<UserOnline> list(){
        return sessionService.list();
    }

    @Log("踢用户下线")
    @RequestMapping("/forceLogout")
    public ResponseEntity forceLogout(String sessionId){
        try{
            sessionService.forceLogout(sessionId);
            return ResponseUtils.success("成功！");
        }catch (Exception e){
            return ResponseUtils.failed(e.getMessage());
        }

    }
}
